Automatically Update YouTube Video Descriptions with Inserted Text

工作流概述

这是一个包含9个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "name": "Automatically Update YouTube Video Descriptions with Inserted Text",
  "tags": [],
  "nodes": [
    {
      "id": "19cafddc-6199-4418-8213-9743c34c9176",
      "name": "Get All Videos",
      "type": "n8n-nodes-base.youTube",
      "position": [
        480,
        380
      ],
      "parameters": {
        "limit": 3,
        "filters": {},
        "options": {
          "order": "date"
        },
        "resource": "video"
      },
      "typeVersion": 1
    },
    {
      "id": "63a6a8e6-994f-46ab-a731-609549fec99f",
      "name": "Update Video Description",
      "type": "n8n-nodes-base.youTube",
      "position": [
        1320,
        460
      ],
      "parameters": {
        "title": "={{ $('Get Specific Video').item.json.snippet.title }}",
        "videoId": "={{ $('Get Specific Video').item.json.id}}",
        "resource": "video",
        "operation": "update",
        "categoryId": "={{ $('Get Specific Video').item.json.snippet.categoryId }}",
        "regionCode": "US",
        "updateFields": {
          "tags": "={{ $('Get Specific Video').item.json.snippet.tags.join() }}",
          "description": "={{ $json.updatedDescription }}"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ce147272-f6c3-4cfb-954b-9a77c63a6232",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        120,
        380
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9ba206b2-1161-41a3-8581-d60dae665096",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        120
      ],
      "parameters": {
        "color": 5,
        "width": 580,
        "height": 180,
        "content": "## Insert Text into YouTube Video Descriptions
**Automatically insert a row of text between two specified rows** in all your YouTube video descriptions. 

This workflow is ideal for YouTubers who need to update multiple video descriptions at once. Easily add a new link or text between existing lines, ensuring consistency across all your video descriptions without manual edits."
      },
      "typeVersion": 1
    },
    {
      "id": "e05f5b9c-c160-45d7-b67a-62d68acc0829",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        560
      ],
      "parameters": {
        "color": 4,
        "width": 340,
        "height": 260,
        "content": "## Configure text string to insert 👆 
Define the text string (row) that will be added to your YouTube video descriptions.

### Variables
- **rowBefore** → The new row will be inserted *after* this line.
- **rowToInsert** -→ The text or link you want to add.
- **rowAfter**→ The new row will be inserted *before* this line.

"
      },
      "typeVersion": 1
    },
    {
      "id": "51a3fd15-8767-4cc0-98a8-fe98ec90db70",
      "name": "Set String to Insert",
      "type": "n8n-nodes-base.set",
      "position": [
        300,
        380
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a05b56b1-6f18-4359-aa4b-127399877301",
              "name": "rowBefore",
              "type": "string",
              "value": "=https://firstlink.com"
            },
            {
              "id": "95ac4a95-cdf4-4d7a-b9a3-78d54c879115",
              "name": "rowToInsert",
              "type": "string",
              "value": "https://mynewlinktoinsert.com"
            },
            {
              "id": "ded86a1f-f0a5-42b8-9176-9be4038f6290",
              "name": "rowAfter",
              "type": "string",
              "value": "https://secondlink.com"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "590b8bb3-6eb4-4bb8-af4c-c2d95221f045",
      "name": "Loop Over Videos",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        700,
        380
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "a80ac941-0a99-4eab-8a6c-effef1e136fa",
      "name": "Get Specific Video",
      "type": "n8n-nodes-base.youTube",
      "position": [
        900,
        460
      ],
      "parameters": {
        "options": {},
        "videoId": "={{ $json.id.videoId }}",
        "resource": "video",
        "operation": "get"
      },
      "typeVersion": 1
    },
    {
      "id": "2c4519e2-1af9-42d7-818c-8165365587fb",
      "name": "Create New Video Description with Row Inserted",
      "type": "n8n-nodes-base.code",
      "position": [
        1100,
        460
      ],
      "parameters": {
        "jsCode": "// Access the input data (YouTube description)
const description = $('Get Specific Video').first().json.snippet.description;
//console.log(inputData)

const variables = $('Set String to Insert').first().json
// Define the rows to search for and the row to insert
const rowBefore = variables.rowBefore;
const rowAfter = variables.rowAfter;
const rowToInsert = variables.rowToInsert;

// Split the description into an array of rows
const rows = description.split(\"\n\");
console.log(rows)
// Find the index of the rowBefore and rowAfter
const indexBefore = rows.findIndex(row => row.trim() === rowBefore);
const indexAfter = rows.findIndex(row => row.trim() === rowAfter);

// Check if both rows are found and rowBefore comes before rowAfter
if (indexBefore !== -1 && indexAfter !== -1 && indexBefore < indexAfter) {
  // Insert the new row between rowBefore and rowAfter
  rows.splice(indexBefore + 1, 0, rowToInsert);
}

// Join the rows back into a single string
const updatedDescription = rows.join(\"\n\");

// Return the updated description in the correct n8n output structure
return [
  {
    json: {
      updatedDescription: updatedDescription
    }
  }
];"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "50fd0bcb-7441-45eb-ab58-ca2a7de78516",
  "connections": {
    "Get All Videos": {
      "main": [
        [
          {
            "node": "Loop Over Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Videos": {
      "main": [
        [],
        [
          {
            "node": "Get Specific Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Specific Video": {
      "main": [
        [
          {
            "node": "Create New Video Description with Row Inserted",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set String to Insert": {
      "main": [
        [
          {
            "node": "Get All Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Video Description": {
      "main": [
        [
          {
            "node": "Loop Over Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Set String to Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New Video Description with Row Inserted": {
      "main": [
        [
          {
            "node": "Update Video Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Youtube
  • Manualtrigger
  • Stickynote
  • Set
  • Splitinbatches

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作